/**************************************************************
 * au  :zhuyehong
 * time:2011.9
 * TABLE begin
 ***************************************************************/

function TABLE(rows, cols, myname, tableID) {
  var table = {};
  table.store = [];
  table.cols = 0;
  table.rows = 0;
  table.pageSize = 20;
  table.page = 0;
  table.pRowB = 0;
  table.myname = 0;
  table.menuPos = 0;
  table.bottomMenu = 0;
  table.tablePos = "";
  table.rowID = 1;
  table.goPage = 1;
  table.title = "0";
  table.warp = 1;
  table.find_result = [];
  table.tr_style = " ";
  table.td_style = " ";
  table.bind_string = "";
  table.cols_resizer = '';

  table.alertTips = "";
  table.bind_botton_name = [];
  table.bind_fun_name = [];
  table.bind_fun_display = [];

  table.data_reload_sw = 0;
  table.data_reload = "";

  table.checkBox = 0;

  table.title_space = [];
  table.title_names = '';
  table.extrenMenuFun = '';

  table.squqre_btn_first = 0;
  table.squqre_btn_last = 0;

  table.view_width = 1440;

  table.BIND = function (bottonName, fun, display) {
    try {
      if (typeof fun != 'function' && bottonName.toString().length == 0) {
        alert("input data is wrong!");
        return;
      }

      table.bind_botton_name.push(bottonName.toString());
      table.bind_fun_name.push(fun);
      var pos = fun.toString().indexOf("(");
      var funName = fun.toString().substr(0, pos);
      pos = funName.indexOf(' ');
      funName = funName.substr(pos + 1) + "()";

      if (0 == table.menuPos) {
        var tmp = "<td min-width='60px'><a><p style='white-space:nowarp;width:60px;cursor:pointer' onclick='func'>bottonName</p></a></td>";

        tmp = tmp.replace("func", funName);
        tmp = tmp.replace("bottonName", bottonName.toString());
        if (display == 1) {
          table.bind_string = table.bind_string + tmp;
        }
      }

      if (2 == table.menuPos) {
        var tmp = "<a href='#' onclick='func'>bottonName</a>";
        tmp = tmp.replace("func", funName);
        tmp = tmp.replace("bottonName", bottonName.toString());
        if (display == 1) {
          table.bind_string = table.bind_string + tmp;
        }
      }
    } catch (e) {
      alert("bind function error!");
    }
  };

  table.getExternMenu = function () {
    if (typeof table.extrenMenuFun == 'function') {
      return table.extrenMenuFun();
    } else {
      return '';
    }
  };

  table.EXEC = function (funname) {
    var index = -1;
    for (var i = 0; i < table.bind_botton_name.length; i++) {
      if (table.bind_botton_name[i] == funname) {
        index = i;
        break;
      }
    }

    if (index != -1) {
      table.bind_fun_name[index]();
    } else {
      alert(" no this function! ");
    }
  };

  table.PRINT = function () {
    alert(table.store);
  };

  table.EMPTY = function () {
    table.store = [];
  };

  table.PUSH_MULTI_DATA = function (data) {
    if (data instanceof Array) {
      table.store = table.store.concat(data);
      table.rows = Math.ceil(table.store.length / table.cols);
    }
  };

  table.SET_CELL = function (row, cols, data) {
    var index = row * table.cols + cols;
    if (data != null) {
      table.store[index] = data;
    } else {
      table.store[index] = " ";
    }

    table.rows = Math.ceil(table.store.length / table.cols);
  };

  table.NEXT_PAGE = function () {
    if (typeof table.alertTips == 'function') {
      table.alertTips();
    }

    var temp_page = table.page;
    var temp_pRowB = table.pRowB;
    table.page = table.page + 1;
    table.pRowB = table.page * table.pageSize;

    if (table.pRowB >= Math.ceil(table.store.length / table.cols)) {
      table.page = temp_page;
      table.pRowB = temp_pRowB;
    }
  };

  table.BACK_PAGE = function () {
    if (typeof table.alertTips == 'function') {
      table.alertTips();
    }

    var temp_page = table.page;
    var temp_pRowB = table.pRowB;
    table.page = table.page - 1;
    table.pRowB = table.page * table.pageSize;

    if (table.pRowB < 0) {
      table.page = temp_page;
      table.pRowB = temp_pRowB;
    }
  };

  table.FIRST_PAGE = function () {
    if (typeof table.alertTips == 'function') {
      table.alertTips();
    }

    table.page = 0;
    table.pRowB = 0;
  };

  table.LAST_PAGE = function () {
    if (typeof table.alertTips == 'function') {
      table.alertTips();
    }

    var temp_page = table.page;
    table.NEXT_PAGE();
    while (table.page != temp_page) {
      temp_page = table.page;
      table.NEXT_PAGE();
    }
  };

  table.GO_PAGE = function () {
    var page = 0;
    var id = "#" + table.myname + "_page_box";
    page = $(id).val();
    table.FIRST_PAGE();
    var temp_page = -1;
    for (var i = 0; i < page; i++) {
      if (table.page == temp_page) {
        break;
      }
      temp_page = table.page;
      table.NEXT_PAGE();
    }
  };

  table.JUMP = function (page) {
    var total = Math.ceil(table.rows / table.pageSize);
    table.page = (page == 'last') ? (total - 1) : page;
    table.pRowB = table.page * table.pageSize;

    /* *** 解决列宽改变后 刷新 表结构破被坏问题 *** */
    var tb = "<table id='paramList'  width='100%' border='0' cellspacing='0' cellpadding='0' class='parameterGrid' style='table-layout:fixed;'  > </table>";
    var parent = $(table.tablePos).parent();
    parent.empty();
    parent.append(tb);
    /* */

    $(table.tablePos).empty();
    $(table.tablePos).append(table.SHOW_TABLE());
  };

  table.MENU_POS2_JUMP = function (node) {
    node = $(node).parent().children()[$(node).parent().children().length - 2];
    var page_num = $(node).val();
    var reg = /^\d+$/;
    var flag = reg.test(page_num.toString());

    page_num = page_num - 1;
    if (page_num >= 0) {
      table.JUMP(page_num);
    }
  };

  table.SELECT_ALL = function () {
    var setname = "#" + myname + "_box";

    if ($(setname).attr("checked") == 'checked') {
      $(':checkbox').attr("checked", true);
    } else {
      $(':checkbox').attr("checked", false);
    }
  };

  table.RELOAD = function () {
    if (typeof table.data_reload == 'function') {
      table.data_reload();

      /* *** 解决列宽改变后 刷新 表结构破被坏问题 *** */
      var tb = "<table id='" + table.tablePos.substring(1, table.tablePos.length) + "'  width='100%' border='0' cellspacing='0' cellpadding='0' class='parameterGrid'  > </table>";
      var parent = $(table.tablePos).parent();
      parent.empty();
      parent.append(tb);
      /* ***** */

      var page = table.page;

      //table.FIRST_PAGE();
      table.page = 0;
      table.pRowB = 0;

      var temp_page = -1;
      for (var i = 0; i < page; i++) {
        if (table.page == temp_page) {
          break;
        }
        temp_page = table.page;

        //table.NEXT_PAGE();
        var temp_page = table.page;
        var temp_pRowB = table.pRowB;
        table.page = table.page + 1;
        table.pRowB = table.page * table.pageSize;

        if (table.pRowB >= Math.ceil(table.store.length / table.cols)) {
          table.page = temp_page;
          table.pRowB = temp_pRowB;
        }
      }

    } else {
      alert("Please init the 'data_reload()' function first!");
    }
  };

  table.Browser360_judge = function () {
    try {
      if (window.external && window.external.twGetRunPath && window.external.twGetRunPath().toLowerCase()) {
        return true;
      }
    } catch (e) {
      return false;
    }
  };

  table.TheWorld_judge = function () {
    var userAgent = navigator.userAgent.toLocaleLowerCase();

    return userAgent.indexOf("theworld") > 0;
  };

  table.SET_TITLE = function (title)//each unit split by ","
  {
    table.title_names = title;
    var titles = title.split(",");

    var resizner = "<div onMouseDown='" + table.myname + ".cols_resizer.MouseDownToResize(this,event)' onMouseMove='" + table.myname + ".cols_resizer.MouseMoveToResize(event)' onMouseUp='" + table.myname + ".cols_resizer.MouseUpToResize(event)' >&nbsp;</div>";

    /* 兼容IE6、IE7 */

    try {
      if (jQuery.browser.msie) {
        var version = jQuery.browser.version;

        //alert(version);
        if (version == '6.0' || version == '7.0') {
          resizner = '';
        }
      }

      if (jQuery.browser.mozilla) {
        resizner = '';
      }

      if (table.TheWorld_judge() == true) {
        resizner = '';
      }
      if (table.Browser360_judge() == true) {
        resizner = '';
      }
    } catch (e) {
    }

    if (table.title_space.length != (titles.length + table.rowID + table.checkBox)) {
      var l = 0;
      for (l = 0; l < titles.length; l++)
        table.title_space[l] = '';
      table.title_space[++l] = '';
      table.title_space[++l] = '';
    }

    var z = 0;
    var first_cell_style = "class='firstCell' ";
    var last_cell_style = "class='lastCell' ";
    if (1 <= titles.length) {
      table.title = "<tr>";
      if (1 == table.rowID) {
        var unit_width = parseInt(parseInt(table.title_space[z++]) / 100 * table.view_width);
        table.title = table.title + "<th nowrap='nowrap' " + first_cell_style + " width='" + unit_width + "' style='cursor:pointer;word-break:keep-all;'>标号</th>";
        first_cell_style = "";
      }

      if (1 == table.checkBox) {
        var unit_width = parseInt(parseInt(table.title_space[z++]) / 100 * table.view_width);
        table.title = table.title + "<th nowrap='nowrap' " + " width='" + unit_width + "' style='cursor:pointer;text-align:center;width:30px;'><input onclick='" + myname + ".SELECT_ALL()' id='" + myname + "_box' type='checkbox' ></th>";
        first_cell_style = "";
      }

      for (var i = 0; i < titles.length; i++) {
        var unit_width = parseInt(parseInt(table.title_space[z++]) / 100 * table.view_width);
        if (i == 0) {
          table.title = table.title + "<th nowrap='nowrap' " + first_cell_style + " onDblClick='" + myname + ".ORDERBY(" + i + ",this)' width='" + unit_width + "' style='cursor:pointer'>" + titles[i] + "</th>";
          first_cell_style = "";
          continue;
        }
        if (i == (titles.length - 1)) {
          table.title = table.title + "<th nowrap='nowrap' " + last_cell_style + " onDblClick='" + myname + ".ORDERBY(" + i + ",this)' width='" + unit_width + "' style='cursor:pointer'>" + titles[i] + "</th>";
          continue;
        }

        table.title = table.title + "<th nowrap='nowrap' " + first_cell_style + " onDblClick='" + myname + ".ORDERBY(" + i + ",this)' width='" + unit_width + "' style='cursor:pointer'>" + titles[i] + resizner + "</th>";

      }

      table.title = table.title + "</tr>";
    }

  };

  table.ORDERBY = function (cols, node) {
    $(node).blur();
    /* 1.先排序； 2.再做块移动
     */

    /*重构数组排序算法*/

    Array.prototype.fst = function (fn, source_data) {

      this.length = 0;

      for (var i = 0; i < source_data.length; i++) {
        this.push(i);
      }

      var fn = fn ||
        function (a, b) {
          var reg = /\d/ig;
          //var f1 = reg.test(a.toString());
          //var f2 = reg.test(b.toString());
          var f1 = a.replace(reg, '');
          var f2 = b.replace(reg, '');
          if (f1 == "" && f2 == "") {
            a = parseInt(a);
            b = parseInt(b);
            return a > b;
          }

          return a < b;

        };
      for (var i = 0; i < this.length; i++) {
        for (var j = i; j < this.length; j++) {
          if (fn(source_data[i], source_data[j]) > 0) {
            var t = this[i];
            this[i] = this[j];
            this[j] = t;

            var m = source_data[i];
            source_data[i] = source_data[j];
            source_data[j] = m;
          }
        }
      }

      return this;
    };
    var stack = [];
    var stackIndex = [];
    colsIndex = $(node).index();

    var i = colsIndex;

    for (var j = 0; i < table.store.length; i = i + table.cols) {
      stack.push(table.store[i]);
      j++;
    }

    var stackIndex = stackIndex.fst(0, stack);

    table.SORT(stackIndex, colsIndex);
  };

  table.SORT = function (index, colsIndex) {
    var dest = [];

    for (var i = 0; i < index.length; i++) {
      var begin = table.cols * index[i];
      var end = begin + table.cols - 1;

      //var xx = table.store[begin];
      //xx = table.store[end];

      for (var j = begin; j <= end; j++) {
        dest.push(table.store[j]);
      }
    }

    table.store = dest;

    /* *** 解决列宽改变后 刷新 表结构破被坏问题 *** */
    var tb = "<table id='" + table.tablePos.substring(1, table.tablePos.length) + "'  width='100%' border='0' cellspacing='0' cellpadding='0' class='parameterGrid' style='table-layout:fixed;'  > </table>";
    var parent = $(table.tablePos).parent();
    parent.empty();
    parent.append(tb);
    /* ***** */

    $(table.tablePos).empty();
    $(table.tablePos).append(table.SHOW_TABLE());
  };

  table.FIND_ITEM = function (itemID, str) {
    if (null != table.store[itemID]) {
      //if(table.store[itemID].match())
    }
  };

  table.FIND_CHANGED = function () {

  };

  table.SHOW_TABLE = function () {
    var index = 0;
    var table_html = "";
    var content = "";
    var i = 0;
    //table.SET_TITLE(table.title_names);
    if ("0" != table.title) {
      table_html = table_html + table.title;
    }

    var trClzFlag = "";
    for (i = table.pRowB; i < (table.rows); i++) {
      if (i - table.pRowB >= table.pageSize)
        break;

      trClzFlag = "";
      if ((i % 2) == 0) {
        trClzFlag = "odd";
      } else {
        trClzFlag = "even";
      }

      table_html = table_html + "<tr name='nochanged' onmouseover='" + table.myname + ".TR_OVER(this)' onmouseout='" + table.myname + ".TR_OUT(this)' id='" + table.myname + "R" + i + "' " + table.tr_style + " class='" + trClzFlag + "'>";

      if (1 == table.rowID) {
        table_html = table_html + "<td style='width:30px;' nowarp><a style='color:gray'>" + i + "</a></td>";
      }

      if (1 == table.checkBox) {
        if (table.store.length == 0) {
          table_html = table_html + "<td style='width:30px;text-align:center;' ><input type='checkbox' style='visibility:hidden' disabled='disabled'></td>";
        } else {
          table_html = table_html + "<td style='width:30px;text-align:center;' ><input type='checkbox'></td>";
        }
      }

      for (var j = 0; j < table.cols; j++) {
        index = (i * table.cols) + (j);
        content = table.store[index];
        if (null != content && content != '') {
          if (table.warp == 0) {
            table_html = table_html + "<td>" + content + "</td>";
          } else {
            table_html = table_html + "<td><div " + table.td_style + " >" + content + "</div></td>";
          }
        } else {
          table_html = table_html + "<td>&nbsp;</td>";
        }
      }
      table_html = table_html + "</tr>";
    }

    var temp_makeup = "";
    while ((i - table.pRowB + 1) <= table.pageSize) {
      trClzFlag = "";
      if (i % 2 == 0) {
        trClzFlag = "odd";
      } else {
        trClzFlag = "even";
      }

      temp_makeup = "<tr class='" + trClzFlag + "'>";
      if (1 == table.rowID) {
        temp_makeup = temp_makeup + "<td style='width:30;'><a style='color:gray'>" + i + "</a></td>";
      }
      if (1 == table.checkBox) {
        temp_makeup = temp_makeup + "<td style='width:30;text-align:center;'><input type='checkbox' style='visibility:hidden' disabled='disabled' /></td>";
      }
      for (var k = 0; k < table.cols; k++) {
        temp_makeup = temp_makeup + "<td><div >&nbsp;</div> </td>";
      }
      temp_makeup = temp_makeup + "</tr>";
      table_html = table_html + temp_makeup;
      i++;
    }
    if (0 == table.menuPos) {
      var colspan = table.cols;
      var bottom_menu = table.bind_string;
      if (1 == table.rowID) {
        colspan = colspan + 1;
      }
      if (1 == table.checkBox) {
        colspan = colspan + 1;
      }
      if (1 == table.goPage) {
        var tmp = "<td min-width='80px'><a><p style='white-space:nowarp;width:80px;cursor:pointer'>To<input id='" + table.myname + "_page_box' onchange='GO_PAGE(" + table.myname + ")' style='margin-left:3px;margin-right:3px;padding:0px;border:1px solid gray;' type='text' size='1'/>Page</p></a></td>";
        bottom_menu = tmp + bottom_menu;
      }
      if (1 == table.data_reload_sw) {
        bottom_menu = bottom_menu + "<td min-width='40px'><a style='cursor:pointer' onclick='RELOAD(" + table.myname + ")'><p style='white-space:nowarp;width:40px;'>" + top.T.BTN.Refresh + "</p></a></td>";
      }
      table_html = table_html + "<tr><td colspan='" + (colspan) + "' align='center'><table width='200' align='center'><tr align='center'><td min-width='30px'><a style='cursor:pointer;' onclick='FIRST_PAGE(" + table.myname + ")'><p style='white-space:nowarp;width:30px;'>Index</p></a></td><td min-width='40px'><a style='cursor:pointer' onclick='BACK_PAGE(" + table.myname + ")'><p style='white-space:nowarp;width:40px;'>" + top.T.BTN.PrePage + "</p></a></td><td min-width='40px'><a style='cursor:pointer' onclick='NEXT_PAGE(" + table.myname + ")'><p style='white-space:nowarp;width:40px;'>" + top.T.BTN.NextPage + "</p></a></td><td min-width='30px'><a style='cursor:pointer' onclick='LAST_PAGE(" + table.myname + ")'><p style='white-space:nowarp;width:30px;'>End</p></a></td><td min-width='55px'><a><p style='white-space:nowarp;width:55px;'>" + (table.page + 1) + "/" + (Math.ceil(table.rows / table.pageSize)) + "</p></a></td>" + bottom_menu + "</tr></table></td></tr>";
    }

    if (1 == table.menuPos) {
      table_html = "<tr style='text-align:center;'><td width='100%' style='padding-left:0;'><table width='100%' height='100%' cellspacing='1' class='grid'>" + table_html + "</table></td><td style='background:transparent;padding-left:0;' height='100%'><table height='100%' cellspacing='1' class='grid' style='background:black;width:60px;'><td align='center' style='vertical-algin:middle' ><a style='cursor:pointer;line-height:10pt;' onclick='FIRST_PAGE(" + table.myname + ")'>首<br>页<br><br></a></td></tr><tr><td align='center'><a style='cursor:pointer;line-height:10pt' onclick='BACK_PAGE(" + table.myname + ")'>上<br>一<br>页<br><br></a></td></tr><tr><td align='center'><a style='cursor:pointer;line-height:10pt' onclick='NEXT_PAGE(" + table.myname + ")'>下<br>一<br>页<br><br></a></td></tr><tr><td align='center'><a style='cursor:pointer;line-height:10pt' onclick='LAST_PAGE(" + table.myname + ")'>尾<br>页<br><br></a></td></tr><tr><td align='center'><a style='line-height:10pt' >第<br>" + table.page + "/" + (Math.ceil(table.rows / table.pageSize) - 1) + "<br>页</a></td></tr></table></td></tr>";
    }

    if (2 == table.menuPos) {
      var bottom_menu = '';
      var colspan = table.cols;

      if (1 == table.rowID) {
        colspan = colspan + 1;
      }
      if (1 == table.checkBox) {
        colspan = colspan + 1;
      }

      var total_page = Math.ceil(table.rows / table.pageSize);

      if (table.page < 3) {
        table.squqre_btn_first = 0;
        table.squqre_btn_last = total_page > 6 ? 6 : total_page;
      } else {
        if (table.page >= (total_page - 3)) {
          //table.squqre_btn_last =  total_page - 1;
          table.squqre_btn_last = total_page;
          table.squqre_btn_first = (total_page - 6) > 0 ? (total_page - 6) : 0;
        } else {
          table.squqre_btn_first = table.page - 3;
          table.squqre_btn_last = (table.page + 3) > total_page - 1 ? (total_page - 1) : (table.page + 3);
        }
      }

      //for(var p=table.squqre_btn_first ; p <=table.squqre_btn_last ; p++)
      for (var p = table.squqre_btn_first; p < table.squqre_btn_last; p++) {
        if (table.page == p) {
          bottom_menu = bottom_menu + "<span class='current'>" + (p + 1) + "</span>";
          continue;
        }

        bottom_menu = bottom_menu + "<a href='#' onclick='" + table.myname + ".JUMP(" + p + ")'>" + (p + 1) + "</a>";
      }

      var b_classCtl = "class='disableA'";
      var e_classCtl = "class='disableA'";

      b_classCtl = (table.page == 0) ? b_classCtl : '';
      e_classCtl = (table.page == (total_page - 1)) ? e_classCtl : '';

      bottom_menu += table.bind_string;
      bottom_menu = "<a href='#' " + b_classCtl + " onclick='" + table.myname + ".JUMP(0)'>第一页</a>" + bottom_menu + "<a href='#' " + e_classCtl + " onclick='" + table.myname + ".JUMP(\"last\")'>End</a>";

      if (table.bottomMenu == 1) {
        var menuButtons = table.getExternMenu();

        var actionMenu = "<tr><td colspan='" + colspan + "' style='text-align:center;'><div style=' display:inline;margin:auto;'>" + menuButtons + "</div></td></tr>";
        table_html = table_html + actionMenu;
      }

      if (table.rows > 200) {
        bottom_menu = bottom_menu + "To" + "<input id='' type='text' size='3' value=''/>" + "页<input type='button' size='2' onclick='" + table.myname + ".MENU_POS2_JUMP(this)' value='GO' />";
      }

      /* 兼容IE6、IE7 */

      if (table.view_width >= 1440) {
        table_html = table_html + "<tr style='height:55px;'><td colspan='" + (colspan) + "' align='left' style='padding-left:200px;' > <div width='50%'><table class='pages' width='500' ><tr><td>" + bottom_menu + "</td></tr></table></div></td></tr>";
      } else {
        try {
          if (jQuery.browser.msie) {
            var version = jQuery.browser.version;
            if (version == '6.0' || version == '7.0') {
              if (version == '6.0') {
                table_html = table_html + "<tr><td colspan='" + (colspan) + "' align='center' > <center width='50%'><table class='pages' width='500' ><tr><td>" + bottom_menu + "</td></tr></table></center></td></tr>";
              }
              if (version == '7.0') {
                table_html = table_html + "<tr><td colspan='" + (colspan) + "' align='center' > <center width='50%'><table class='pages' width='500' ><tr><td>" + bottom_menu + "</td></tr></table></center></td></tr>";
              }
            } else {
              table_html = table_html + "<tr><td colspan='" + (colspan) + "'><div style='display:block;'><table class='pages' width='500' style='margin:auto;' ><tr><td>" + bottom_menu + "</td></tr></table></div></td></tr>";
            }
          } else {
            table_html = table_html + "<tr><td colspan='" + (colspan) + "'><div style='display:block;'><table class='pages' width='500' style='margin:auto;' ><tr><td>" + bottom_menu + "</td></tr></table></div></td></tr>";
          }
        } catch (e) {
        }

      }

    }
    //alert(table_html);
    return table_html;
  };

  table.TR_OVER = function (node) {
    var input = $(node).children(".textInputActive");
    if (input.length == 0) {
      $(node).addClass("hoverTd");
    }
  };

  table.TR_OUT = function (node) {
    $(node).removeClass("hoverTd");
  };
  table.INIT = function () {
    table.cols = cols;
    table.rows = rows;
    table.myname = myname;
    table.tablePos = "#" + tableID;

    try {
      table.cols_resizer = TB_RESIZER(tableID);
    } catch (e) {
      table.cols_resizer = '';
    }
  };

  table.INIT();
  return table;
}

function NEXT_PAGE(myname) {
  myname.NEXT_PAGE();
  $(myname.tablePos).empty();
  $(myname.tablePos).append(myname.SHOW_TABLE());
}

function BACK_PAGE(myname) {
  myname.BACK_PAGE();
  $(myname.tablePos).empty();
  $(myname.tablePos).append(myname.SHOW_TABLE());
}

function FIRST_PAGE(myname) {
  myname.FIRST_PAGE();
  $(myname.tablePos).empty();
  $(myname.tablePos).append(myname.SHOW_TABLE());
}

function LAST_PAGE(myname) {
  myname.LAST_PAGE();
  $(myname.tablePos).empty();
  $(myname.tablePos).append(myname.SHOW_TABLE());
}

function GO_PAGE(myname) {
  myname.GO_PAGE();
  $(myname.tablePos).empty();
  $(myname.tablePos).append(myname.SHOW_TABLE());
}

function RELOAD(myname) {
  myname.RELOAD();

  /* *** 解决列宽改变后 刷新 表结构破被坏问题 *** */
  var tb = "<table id='" + myname.tablePos.substring(1, myname.tablePos.length) + "'  width='100%' border='0' cellspacing='0' cellpadding='0' class='parameterGrid' style='table-layout:fixed;'  > </table>";
  var parent = $(myname.tablePos).parent();
  parent.empty();
  parent.append(tb);
  /* ***** */

  $(myname.tablePos).empty();
  $(myname.tablePos).append(myname.SHOW_TABLE());
}

function TB_RESIZER(tbName) {
  var resizer = {
    table_name: '#theObjTable',
    obj: '',
    contentWindow: ''
  };

  resizer.MouseDownToResize = function (obj, ev) {
    try {
      ev = ev ? ev : window.event;
    } catch (e) {
    }

    resizer.obj = obj;
    resizer.setTableLayoutToFixed();
    obj.mouseDownX = ev.clientX;

    obj.pareneTdW = $(obj).parent()[0].offsetWidth;

    if (window.attachEvent) {
      $(resizer.table_name).parent().css("overflow-x", "hidden");
      obj.setCapture();
    } else {
      resizer.contentWindow.addEventListener('mouseup', resizer.MouseUpToResize, true);
      resizer.contentWindow.addEventListener('click', resizer.MouseUpToResize, true);
      resizer.contentWindow.addEventListener("mousemove", resizer.MouseMoveToResize, false);
    }
  };

  resizer.MouseMoveToResize = function (ev) {
    if (!resizer.obj)
      return false;

    obj = resizer.obj;

    if (!obj.mouseDownX)
      return false;

    try {
      ev = ev ? ev : window.event;
    } catch (e) {
    }

    var newWidth = obj.pareneTdW * 1 + ev.clientX * 1 - obj.mouseDownX;

    if (newWidth > 0) {
      $(obj).parent().css("width", newWidth);
      var width = obj.pareneTdW * 1 + ev.clientX * 1 - obj.mouseDownX;

      if (window.attachEvent) {
        $(resizer.table_name).css("width", width);
      } else {
        var oldwidth = $(resizer.table_name).css("width");

        oldwidth = parseInt(oldwidth.substring(0, oldwidth.length - 2));
        var td_oldwidth = $(resizer.obj).parent().css("width");

        td_oldwidth = parseInt(td_oldwidth.substring(0, td_oldwidth.length - 2));
        $(resizer.obj).parent().css("width", (td_oldwidth + width - obj.pareneTdW));
      }

    }
    if (window.attachEvent) {
      obj.setCapture();
    }
  };

  resizer.MouseUpToResize = function (ev) {
    obj = resizer.obj;
    if (window.attachEvent) {
      obj.releaseCapture();
    } else {
      resizer.contentWindow.removeEventListener('mouseup', resizer.MouseUpToResize, true);
      resizer.contentWindow.removeEventListener('click', resizer.MouseUpToResize, true);
      resizer.contentWindow.removeEventListener("mousemove", resizer.MouseMoveToResize, false);
    }
    obj.mouseDownX = 0;
    resizer.obj = '';
    $(resizer.table_name).parent().css("overflow-x", "auto");
  };

  resizer.setTableLayoutToFixed = function () {
    if ($(resizer.table_name).css("tableLayout") == 'fixed') {
      return;
    }
    try {
      var headerTr = $(resizer.table_name)[0].rows[0];
      for (var i = 0; i < headerTr.cells.length; i++) {
        headerTr.cells[i].style.OffsetWidth = headerTr.cells[i].offsetWidth;
      }

      for (var i = 0; i < headerTr.cells.length; i++) {
        headerTr.cells[i].style.width = headerTr.cells[i].style.OffsetWidth;
      }
    } catch (e) {
      alert(e.description);
    }
    $(resizer.table_name).css("tableLayout", 'fixed');
  };

  resizer.firefoxStop = function () {
    obj.removeEventListener("mousemove", resizer.MouseMoveToResize, false);
    obj.removeEventListener('click', resizer.MouseUpToResize, false);
    resizer.obj.mouseDownX = 0;
    resizer.obj = '';

    $(resizer.table_name).parent().css("overflow-x", "auto");
  };

  resizer.INIT = function () {
    resizer.table_name = '#' + tbName;

    if (window.attachEvent) {

    } else {
      resizer.contentWindow = parent.document.getElementById('contentMainFrame').contentWindow.document;
    }
  };

  resizer.INIT();

  return resizer;
}
